package org.example.cet.demos.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.example.cet.demos.converter.converter;
import org.example.cet.demos.domain.PageBean;
import org.example.cet.demos.domain.dto.ClassroomDto;
import org.example.cet.demos.domain.po.Classroom;
import org.example.cet.demos.domain.po.Teacher;
import org.example.cet.demos.domain.query.TeacherQuery;
import org.example.cet.demos.mapper.TeacherMapper;
import org.example.cet.demos.service.ITeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hq
 * @since 2024-12-18
 */
@Service
@RequiredArgsConstructor
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements ITeacherService {
    private final converter converter;

    public PageBean getPage(TeacherQuery teacherQuery){
        Page<Teacher> page=new Page<>(teacherQuery.getCurrentPage(), teacherQuery.getPageSize());
        lambdaQuery().like(teacherQuery.getId()!=null,Teacher::getId,teacherQuery.getId())
                .like(!StrUtil.isBlankIfStr(teacherQuery.getName()),Teacher::getName,teacherQuery.getName())
                .like(!StrUtil.isBlankIfStr(teacherQuery.getDepartment()),Teacher::getDepartment,teacherQuery.getDepartment())
                .page(page);
        PageBean pageBean=new PageBean();
        pageBean.setTotal(page.getTotal());
        pageBean.setRows(page.getRecords());
        return pageBean;
    }

    @Autowired
    private TeacherMapper teacherMapper;
    @Override
    public List<ClassroomDto> findClass(Long id) {
        return teacherMapper.findClass(id);
    }

    public List<Teacher> getList(){
        return teacherMapper.getList();
    }
}
